/*
 * Copyright 2010 Mttang.com All right reserved. This software is the confidential and proprietary information of
 * Mttang.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Mttang.com.
 */
package com.mttang.sys.biz.service.support;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.mttang.framework.core.service.AbstractService;
import com.mttang.info.core.ParameterModel;
import com.mttang.info.core.ParameterModelWrapper;
import com.mttang.info.core.ResultDTO;
import com.mttang.sys.biz.service.SystemLogService;
import com.mttang.sys.biz.service.UserService;
import com.mttang.sys.dto.UserDTO;
import com.mttang.sys.integration.dao.UserDAO;
import com.mttang.util.SysBeanConstant;

/**
 * 类UserServiceImpl.java的实现描述：TODO 类实现描述
 * 
 * @author acc 2010-5-31 下午04:54:19
 */
public class UserServiceImpl extends AbstractService implements UserService {

    private Log logger = LogFactory.getLog(getClass());

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#delete(com.mttang.sys.dto.UserDTO)
     */
    @Override
    public void delete(UserDTO dto,Map<Object, Object> logMap) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---delete");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        dao.delete(dto);
        
//      //写日志
//        SystemLogService systemLogService = (SystemLogServiceImpl)context.getBean(SysBeanConstant.SERVICE_SYSTEMLOG);
//        systemLogService.addLog(logMap);
    }

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#findById(java.lang.Integer)
     */
    @Override
    public UserDTO findById(Integer id) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---findById");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        return dao.findById(id);
    }

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#findCount(java.util.Map)
     */
    @Override
    public Long findCount(Map<String, Object> param) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---findCount");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        return dao.findCount(param);
    }

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#findUser(java.util.Map)
     */
    @Override
    public ResultDTO<UserDTO> findUser(ParameterModel parameter) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---findUser");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        ParameterModelWrapper wrapper = new ParameterModelWrapper(parameter);
        Map<String, Object> param = wrapper.wrap();
        Long count = dao.findCount(param);
        parameter.getPagedFliper().setRecordCount(count.intValue());
        ResultDTO<UserDTO> result = new ResultDTO<UserDTO>();
        result.setDtoClass(UserDTO.class);
        result.setTotalRecord(count);
        param = wrapper.wrap();
        result.setRecords(dao.findUser(param));
        return result;
    }
    
    @Override
    public List<Map<String, Object>> findAllUserList(Map<String, Object> param){
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        return dao.findAllUserList(param);
    }

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#insert(com.mttang.sys.dto.UserDTO)
     */
    @Override
    public void insert(UserDTO dto,Map<Object, Object> logMap) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---insert");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        dao.insert(dto);
        
//      //写日志
//        SystemLogService systemLogService = (SystemLogServiceImpl)context.getBean(SysBeanConstant.SERVICE_SYSTEMLOG);
//        systemLogService.addLog(logMap);
        
    }

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#login(com.mttang.sys.dto.UserDTO)
     */
    @Override
    public UserDTO login(UserDTO dto,Map<Object, Object> logMap) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---login");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        
        
//      //写日志
//        SystemLogService systemLogService = (SystemLogServiceImpl)context.getBean(SysBeanConstant.SERVICE_SYSTEMLOG);
//        systemLogService.addLog(logMap);
        return dao.login(dto);
    }

    /*
     * (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#update(com.mttang.sys.dto.UserDTO)
     */
    @Override
    public void update(UserDTO dto,Map<Object, Object> logMap) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---update");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        dao.update(dto);
//      //写日志
//        SystemLogService systemLogService = (SystemLogServiceImpl)context.getBean(SysBeanConstant.SERVICE_SYSTEMLOG);
//        systemLogService.addLog(logMap);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#findByEmpno(java.lang.String)
     */
    @Override
    public UserDTO findByEmpno(String empno) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---findByEmpno");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        return dao.findByEmpno(empno);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.biz.service.UserService#updateByEmpno(com.mttang.sys.dto.UserDTO)
     */
    @Override
    public void updateByEmpno(UserDTO dto,Map<Object, Object> logMap) {
        // TODO Auto-generated method stub
        if (logger.isInfoEnabled()) {
            logger.info("---UserServiceImpl---updateByEmpno");
        }
        UserDAO dao = (UserDAO) context.getBean(SysBeanConstant.DAO_USER);
        dao.updateByEmpno(dto);
    }

}
